home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 13 / QRZ Ham Radio Callsign Database - Volume 13.iso / unix / src / nsort.c < prev    next >
C/C++ Source or Header  |  1996-06-23  |  824b  |  55 lines

  1.  
  2. #include "cb.h"
  3.  
  4. main(argc,argv)
  5. int argc;
  6. char *argv[];
  7. {
  8.     int cmp_node();
  9.     caddr_t mc;
  10.     caddr_t mi;
  11.     caddr_t end;
  12.     struct stat st;
  13.     struct nind *idx;
  14.     struct nind key;
  15.     struct nind *found;
  16.     int    dir;
  17.     long    p;
  18.     long    idsize;
  19.     int    nel;
  20.     FILE *fp;
  21.  
  22.     int IS = sizeof(struct nind);
  23.  
  24.     if ((fp=fopen("nlist.ndx","r+")) == NULL)
  25.     {
  26.         printf("Error opening nlist.ndx\n");
  27.         exit(1);
  28.     }
  29.     fstat(fileno(fp),&st);
  30.     if ((mi = (caddr_t)mmap(NULL,st.st_size,PROT_READ|PROT_WRITE,MAP_SHARED,
  31.         fileno(fp),NULL)) == (caddr_t)NULL)
  32.     {
  33.         fprintf(stderr,"Error - mmap index file\n");
  34.         exit(1);
  35.     }
  36.     fclose(fp);
  37.  
  38.     idsize = st.st_size/IS;
  39.     idx = (struct nind *)mi;
  40.  
  41.     qsort((char *)idx, idsize, sizeof(struct nind), cmp_node);
  42.  
  43.     munmap(mi,st.st_size);
  44.     
  45.     exit(0);
  46.  
  47. }
  48.  
  49. cmp_node(i1,i2)
  50. struct nind *i1, *i2;
  51. {
  52.     return(strcmp(i1->name,i2->name));
  53. }
  54.  
  55.